// 导入
import request from "@/utils/request";
// 导入接口的类型
import type { SpuResponseData } from "./type/index";
// 定义枚举类型
enum API {
  // 获取到的是已有的SPU的数据
  SPULIST_URL = "/admin/product/",
  // 获取全部品牌接口
  ALLTRADEMARK_URL = "/admin/product/baseTrademark/getTrademarkList",
  // 获取到的是品牌的图片
  SPUIMAGELIST_URL = "/admin/product/spuImageList/",
  // 获取到的是手机版本型号和颜色
  SPUSALEATTRLIST_URL = "/admin/product/spuSaleAttrList/",
  // 获取到的是手机的版本
  SPUBASESALEATTRLIST_URL = "/admin/product/baseSaleAttrList",
  // 新增SPU
  SPUADD_URL = "/admin/product/saveSpuInfo",
  // 修改SPU
  UPDATESPU_URL = "/admin/product/updateSpuInfo",
  // 获取全部的平台属性
  ATTR_URL = "/admin/product/attrInfoList/",
  // 添加一个sku
  SKUADD_URL = "/admin/product/saveSkuInfo",
  // 删除一个
  SPUDELETE_URL = "/admin/product/deleteSpu/",
  // 查看详情
  FINDSKULIST_URL = "/admin/product/findBySpuId/",
}
// 获取SPU的数据
export const reqSpuList = (
  page: number,
  limit: number,
  category3Id: number | string
) =>
  request.get<any, SpuResponseData>(
    API.SPULIST_URL + `${page}/${limit}/?category3Id=${category3Id}`
  );
// 获取全部的SPU的品牌的数据
export const reqAllTradeMark = () =>
  request.get<any, any>(API.ALLTRADEMARK_URL);
// 获取到全部sku品牌的图片
export const reqSkuImageList = (spuId: number) =>
  request.get<any, any>(API.SPUIMAGELIST_URL + spuId);
// 获取到的是手机版本型号的信息需要携带ID
export const reqSpuSaleAttr = (spuId: number) =>
  request.get<any, any>(API.SPUSALEATTRLIST_URL + spuId);
// 获取到的是商品全部的版本信息
export const reqSpuBaseAttrList = () =>
  request.get<any, any>(API.SPUBASESALEATTRLIST_URL);
// 获取添加和更新的最新的函数
export const reqAddOrUpdateSpu = (data: any) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data);
  } else {
    return request.post<any, any>(API.SPUADD_URL, data);
  }
};
// 发送全部的请求
export const reqAllAttrList = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string
) =>
  request.get<any, any>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`
  );
// 添加一个sku
export const reqAddSku = (data: any) =>
  request.post<any, any>(API.SKUADD_URL, data);
// 查看sku
export const reqSkuList = (spuId: any) =>
  request.get<any, any>(API.FINDSKULIST_URL + spuId);
// 删除sku
export const reqDeleteSpu = (spuId: any) =>
  request.delete<any, any>(API.SPUDELETE_URL + spuId);
